package views

import (
	"haiqiu-blog-go/common"
	"haiqiu-blog-go/service"
	"log"
	"net/http"
	"strconv"
)

func (*HTMLApi) Index(w http.ResponseWriter, r *http.Request) {
	index := common.Template.Index
	if err := r.ParseForm(); err != nil {
		log.Println(err)
		index.WriteError(w, err)
	}
	pageStr := r.Form.Get("page")
	page := 1
	if pageStr != "" {
		page, _ = strconv.Atoi(pageStr)
	}
	pageSize := 10
	//页面上涉及到的所有的数据，必须有定义
	hr, err := service.GetAllIndexInfo(page, pageSize)
	if err != nil {
		log.Println(err)
		index.WriteError(w, err)
	}
	index.WriteData(w, hr)

}
